package com.atguigu.study.callable;

import java.sql.Time;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;

//class MyThreads implements Callable<Integer>{
//    @Override
//    public Integer call() throws Exception {
//        System.out.println(Thread.currentThread().getName()+"-----come in call method");
//        try {
//            TimeUnit.SECONDS.sleep(3);
//        } catch (InterruptedException e) {
//            throw new RuntimeException(e);
//        }
//        return 1229;
//    }
//}
public class CallableDemoo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
//        FutureTask<Integer> futureTask1 = new FutureTask<>(new MyThreads());
        FutureTask<Integer> futureTask1 = new FutureTask<>(()->{
            System.out.println(Thread.currentThread().getName()+"come in call method");
            try {
          TimeUnit.SECONDS.sleep(3);
            } catch (InterruptedException e) {
           throw new RuntimeException(e);
            }
            return 1229;
        });
        Thread threadA = new Thread(futureTask1, "A");
        threadA.start();
        System.out.println(futureTask1.get());

//        FutureTask<Integer> futureTask2 = new FutureTask<>(new MyThreads());
        FutureTask<Integer> futureTask2 = new FutureTask<>(()->{
            System.out.println(Thread.currentThread().getName()+"come in call method");
            return 1229;});
        Thread threadB = new Thread(futureTask2,"B");
        threadB.start();
        System.out.println(Thread.currentThread().getName()+"-----over");
    }
}
